package vehicle;

import statemap.State;

public class StoplightContext extends statemap.FSMContext {

	private static final long serialVersionUID = 1L;

	public StoplightContext(Stoplight owner) {
		super(StopMap.Stopped);
		_owner = owner;
	}

	public StoplightContext(Stoplight owner, StoplightState initState) {
		super(initState);
		_owner = owner;
	}

	public void enterStartState() {
		getState().Entry(this);
		return;
	}

	public void Continue() {
		_transition = "Continue";
		getState().Continue(this);
		_transition = "";
		return;
	}

	public void Pause() {
		_transition = "Pause";
		getState().Pause(this);
		_transition = "";
		return;
	}

	public void Start() {
		_transition = "Start";
		getState().Start(this);
		_transition = "";
		return;
	}

	public void Stop() {
		_transition = "Stop";
		getState().Stop(this);
		_transition = "";
		return;
	}

	public void Timeout() {
		_transition = "Timeout";
		getState().Timeout(this);
		_transition = "";
		return;
	}

	public StoplightState getState() throws statemap.StateUndefinedException {
		if (_state == null) {
			throw (new statemap.StateUndefinedException());
		}
		return ((StoplightState) _state);
	}

	protected Stoplight getOwner() {
		return (_owner);
	}

	public void setOwner(Stoplight owner) {
		if (owner == null) {
			throw (new NullPointerException("null owner"));
		} else {
			_owner = owner;
		}
		return;
	}

	transient private Stoplight _owner;

	public static abstract class StoplightState extends State {

		private static final long serialVersionUID = 1L;

		protected StoplightState(String name, int id) {
			super(name, id);
		}

		protected void Entry(StoplightContext context) {
		}

		protected void Exit(StoplightContext context) {
		}

		protected void Continue(StoplightContext context) {
			Default(context);
		}

		protected void Pause(StoplightContext context) {
			Default(context);
		}

		protected void Start(StoplightContext context) {
			Default(context);
		}

		protected void Stop(StoplightContext context) {
			Default(context);
		}

		protected void Timeout(StoplightContext context) {
			Default(context);
		}

		protected void Default(StoplightContext context) {
			throw (new statemap.TransitionUndefinedException("State: "
					+ context.getState().getName() + ", Transition: "
					+ context.getTransition()));
		}
	}

	static abstract class StopMap {

		public static final StopMap_Stopped Stopped = new StopMap_Stopped(
				"StopMap.Stopped", 0);
		public static final StopMap_EastWestGreen EastWestGreen = new StopMap_EastWestGreen(
				"StopMap.EastWestGreen", 1);
		public static final StopMap_EastWestYellow EastWestYellow = new StopMap_EastWestYellow(
				"StopMap.EastWestYellow", 2);
		public static final StopMap_NorthSouthGreen NorthSouthGreen = new StopMap_NorthSouthGreen(
				"StopMap.NorthSouthGreen", 3);
		public static final StopMap_NorthSouthYellow NorthSouthYellow = new StopMap_NorthSouthYellow(
				"StopMap.NorthSouthYellow", 4);
		private static final StopMap_Default Default = new StopMap_Default(
				"StopMap.Default", -1);

		public static StopMap_Stopped getStopped() {
			return Stopped;
		}

		public static StopMap_EastWestGreen getEastwestgreen() {
			return EastWestGreen;
		}

		public static StopMap_EastWestYellow getEastwestyellow() {
			return EastWestYellow;
		}

		public static StopMap_NorthSouthGreen getNorthsouthgreen() {
			return NorthSouthGreen;
		}

		public static StopMap_NorthSouthYellow getNorthsouthyellow() {
			return NorthSouthYellow;
		}

		public static StopMap_Default getDefault() {
			return Default;
		}
	}

	protected static class StopMap_Default extends StoplightState {

		private static final long serialVersionUID = 1L;

		protected StopMap_Default(String name, int id) {
			super(name, id);
		}

		protected void Start(StoplightContext context) {

			return;
		}

		protected void Continue(StoplightContext context) {

			return;
		}

		protected void Pause(StoplightContext context) {
			Stoplight ctxt = context.getOwner();

			StoplightState endState = context.getState();

			context.clearState();
			try {
				ctxt.PauseTimer();
			} finally {
				context.setState(endState);
				context.pushState(PauseMap1.Paused);
				(context.getState()).Entry(context);
			}
			return;
		}

		protected void Stop(StoplightContext context) {
			Stoplight ctxt = context.getOwner();

			(context.getState()).Exit(context);
			context.clearState();
			try {
				ctxt.StopTimer();
				ctxt.InitLights();
			} finally {
				context.setState(StopMap.Stopped);
				(context.getState()).Entry(context);
			}
			return;
		}
	}

	private static final class StopMap_Stopped extends StopMap_Default {

		private static final long serialVersionUID = 1L;

		private StopMap_Stopped(String name, int id) {
			super(name, id);
		}

		protected void Continue(StoplightContext context) {
			return;
		}

		protected void Pause(StoplightContext context) {

			return;
		}

		protected void Start(StoplightContext context) {
			Stoplight ctxt = context.getOwner();

			(context.getState()).Exit(context);
			context.clearState();
			try {
				ctxt.InitLights();
				ctxt.TurnLight("NSLIGHT", "RED");
				ctxt.TurnLight("EWLIGHT", "GREEN");
				ctxt.InformCanvas("EastWest");
				ctxt.SetTimer("EastWest");
			} finally {
				context.setState(StopMap.EastWestGreen);
				(context.getState()).Entry(context);
			}
			return;
		}

		protected void Stop(StoplightContext context) {
			return;
		}
	}

	private static final class StopMap_EastWestGreen extends StopMap_Default {

		private static final long serialVersionUID = 1L;

		private StopMap_EastWestGreen(String name, int id) {
			super(name, id);
		}

		protected void Timeout(StoplightContext context) {
			Stoplight ctxt = context.getOwner();

			(context.getState()).Exit(context);
			context.clearState();
			try {
				ctxt.TurnLight("EWLIGHT", "YELLOW");
				ctxt.InformCanvas("YELLOW");
				ctxt.SetTimer("Yellow");
			} finally {
				context.setState(StopMap.EastWestYellow);
				(context.getState()).Entry(context);
			}
			return;
		}
	}

	private static final class StopMap_EastWestYellow extends StopMap_Default {

		private static final long serialVersionUID = 1L;

		private StopMap_EastWestYellow(String name, int id) {
			super(name, id);
		}

		protected void Timeout(StoplightContext context) {
			Stoplight ctxt = context.getOwner();

			(context.getState()).Exit(context);
			context.clearState();
			try {
				ctxt.TurnLight("EWLIGHT", "RED");
				ctxt.TurnLight("NSLIGHT", "GREEN");
				ctxt.InformCanvas("NorthSouth");
				ctxt.SetTimer("NorthSouth");
			} finally {
				context.setState(StopMap.NorthSouthGreen);
				(context.getState()).Entry(context);
			}
			return;
		}
	}

	private static final class StopMap_NorthSouthGreen extends StopMap_Default {

		private static final long serialVersionUID = 1L;

		private StopMap_NorthSouthGreen(String name, int id) {
			super(name, id);
		}

		protected void Timeout(StoplightContext context) {
			Stoplight ctxt = context.getOwner();

			(context.getState()).Exit(context);
			context.clearState();
			try {
				ctxt.TurnLight("NSLIGHT", "YELLOW");
				ctxt.InformCanvas("YELLOW");
				ctxt.SetTimer("Yellow");
			} finally {
				context.setState(StopMap.NorthSouthYellow);
				(context.getState()).Entry(context);
			}
			return;
		}
	}

	private static final class StopMap_NorthSouthYellow extends StopMap_Default {

		private static final long serialVersionUID = 1L;

		private StopMap_NorthSouthYellow(String name, int id) {
			super(name, id);
		}

		protected void Timeout(StoplightContext context) {
			Stoplight ctxt = context.getOwner();

			(context.getState()).Exit(context);
			context.clearState();
			try {
				ctxt.TurnLight("NSLIGHT", "RED");
				ctxt.TurnLight("EWLIGHT", "GREEN");
				ctxt.InformCanvas("EastWest");
				ctxt.SetTimer("EastWest");
			} finally {
				context.setState(StopMap.EastWestGreen);
				(context.getState()).Entry(context);
			}
			return;
		}
	}

	static abstract class PauseMap1 {

		public static final PauseMap1_Paused Paused = new PauseMap1_Paused(
				"PauseMap1.Paused", 5);
		public static final PauseMap1_PauseTimeout PauseTimeout = new PauseMap1_PauseTimeout(
				"PauseMap1.PauseTimeout", 6);
		private static final PauseMap1_Default Default = new PauseMap1_Default(
				"PauseMap1.Default", -1);

		public static PauseMap1_Paused getPaused() {
			return Paused;
		}

		public static PauseMap1_PauseTimeout getPausetimeout() {
			return PauseTimeout;
		}

		public static PauseMap1_Default getDefault() {
			return Default;
		}
	}

	protected static class PauseMap1_Default extends StoplightState {

		private static final long serialVersionUID = 1L;

		protected PauseMap1_Default(String name, int id) {
			super(name, id);
		}

		protected void Start(StoplightContext context) {

			return;
		}

		protected void Pause(StoplightContext context) {

			return;
		}

		protected void Stop(StoplightContext context) {

			(context.getState()).Exit(context);
			context.popState();

			context.Stop();
			return;
		}
	}

	private static final class PauseMap1_Paused extends PauseMap1_Default {

		private static final long serialVersionUID = 1L;

		private PauseMap1_Paused(String name, int id) {
			super(name, id);
		}

		protected void Continue(StoplightContext context) {
			Stoplight ctxt = context.getOwner();

			(context.getState()).Exit(context);
			context.clearState();
			try {
				ctxt.ContinueTimer();
			} finally {
				context.popState();
			}

			context.Continue();
			return;
		}

		protected void Timeout(StoplightContext context) {

			(context.getState()).Exit(context);
			context.setState(PauseMap1.PauseTimeout);
			(context.getState()).Entry(context);
			return;
		}
	}

	private static final class PauseMap1_PauseTimeout extends PauseMap1_Default {

		private static final long serialVersionUID = 1L;

		private PauseMap1_PauseTimeout(String name, int id) {
			super(name, id);
		}

		protected void Continue(StoplightContext context) {
			(context.getState()).Exit(context);
			context.popState();

			context.Timeout();
			return;
		}
	}
}